<?php
    require_once(dirname(dirname(__DIR__)).
        DIRECTORY_SEPARATOR.
        "inc".
        DIRECTORY_SEPARATOR.
        "incFunctions.php"
    );
    
    # Ei kirjautumista
    if (!API::logged()) {
        die("Access denied!");
    }        
?>
<nav class="navbar navbar-default navbar-fixed-top" id="nav-navbar" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="a-navigation navbar-brand" data-ui-view="main" href="#">GymDB</a>
        </div>
        
        <div class="collapse navbar-collapse" id="navbar">
            <ul class="nav navbar-nav">
                <?php
                    foreach (Menu::getMenu() as $root => $submenu) {
                        # Tätä ei tulosteta
                        if ($root == "main") {
                            continue;
                        }
                        
                        # Useampi kuin yksi alinäkymä
                        if (count($submenu) > 1) {
                            $title = htmlescape(Menu::getMenuTitle($root));
                            echo <<<HTML
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">$title <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
HTML;

                            foreach ($submenu as $view => $isView) {
                                $dataView   = (($isView) ? "view" : "action");
                                $title      = htmlescape(Menu::getViewTitle($view));
                                echo <<<HTML
                        <li>
                            <a class="a-navigation" data-ui-$dataView="$view" href="#">$title</a>
                        </li>
HTML;
                            }
                            
                            echo <<<HTML
                    </ul>
                </li>
HTML;
                        } else { # Vain yksi alinäkymä
                            $view       = array_keys($submenu)[0];
                            $dataView   = (($submenu[$view]) ? "view" : "action");
                            $title      = htmlescape(Menu::getViewTitle($view));
                            echo <<<HTML
                <li>
                    <a class="a-navigation" data-ui-$dataView="$view" href="#">$title</a>
                </li>
HTML;
                        }
                    }
                ?>
            </ul>
        </div>
    </div>
</nav>